/**
 * Created by oneminute on 7/28/14.
 */

var assert = require("assert");
var should = require("should");
var logger = require("../../lib/utils/logger");
var testutils = require("../testutils");
var lz = require("../../lib/utils/modules")();
var httpMocks = require("../lib/http-mock");
var async = require("async");
var path = require("path");
var releaseneed = require("../../routes/releaseneed");
var userFilter = require("../../routes/userfilter");

describe("测试routes/releaseneed模块。", function () {

    var user = null;
    before(function (done) {
        user = new lz.User({
            id: lz.Utils.getUUID("u_"),
            name: lz.Utils.getRandName()
        });
        user.save(function (_err, _user) {
            done();
        })
    });

    it("正常发布需求。", function (done) {
        var request = httpMocks.createExpressRequest({
            method: 'GET',
            url: '/releaseneed?uid=' + user.id,
            files: {
            },
            body: {
                description: "测试需求描述"
            }
        });
        var response = httpMocks.createExpressResponse();

        var getFn = releaseneed.post.bind(null, request, response, {}, function (_err, _user, _args) {
            var user = new lz.User({_id: _user._id});
            user.load(function (_err, _user) {
                testutils.check(done, function () {
                    assert.equal(_user.demands.length, 1);
                    _user.demands[0].description.should.equal("测试需求描述");
                });
            });
        });
        userFilter(request, response, getFn);
    });

    after(function (done) {
        user.refresh(function() {
            user.delete(function () {
                done();
            });
        });
    });
});